angular.module('wfTaskUserAddApp', []).controller( 'wfTaskUserAddCtr',
	function($scope, $http) {
	  $scope.wfTaskId = angular.element($("#id")).val();  //获取ID
	  $scope.taskName = angular.element($("#taskName")).val();  //获取任务名称
	  $scope.wfFlowId = angular.element($("#wfFlowId")).val();  //获取动态流程ID 
	  $scope.taskId = angular.element($("#taskId")).val();  //获取动态流程ID  
	  $scope.productHis=[];
	  $scope.sj = function(){ 
			$('#sjCode').modal({
				remote: basePath+'/system/flowManager/user_search.jsp'  })
	  };
	  $scope.removeHis = function (index) {
		    $scope.productHis.splice(index, 1);
	  }
	 

      $http({  
    		url:basePath+'/flowManager/queryAllTaskUserDataList',  
    		params: {  
    			'id':$scope.wfTaskId  
    	    },  
    		method:'POST'  
    		}).success(function(data,header,config,status){
    			if(data.rows){
    				$scope.productHis = data.rows;
    			}
    		
    		}).error(function(data,header,config,status){  
    			  toastr.warning("操作失败！");  
      		});

        // 点击保存按钮，新增一条数据
		$scope.saveWfTaskUser = function() {
				submitData();
			//}
		};	
		
		
	
		
		// form表单提交方法 submit(若是校验都通过啦，数据便可以提交啦)  
		function submitData() {
			if($scope.productHis){
				for(var i=0;i<$scope.productHis.length;i++){
					$scope.productHis[i].wfFlowId=$scope.wfFlowId;
					$scope.productHis[i].wfTaskId= $scope.wfTaskId;
					$scope.productHis[i].taskId= $scope.taskId;
				}
			}
			var json = JSON.stringify( $scope.productHis);
			$http({
				url : basePath+'/flowManager/insertBatchTaskUser',
				method : 'POST',
				params :{'json':json}
				
			}).success(function(data, header, config, status) {
				toastr.success("操作成功");
				setTimeout(function() {
					location.href = basePath+'/system/flowManager/wftask_list.jsp?id='+ $scope.wfFlowId ;
				}, 500);
			}).error(function(data, header, config, status) {
				toastr.error("调用错误！");
				setTimeout(function() {
					location.href = basePath+'/system/flowManager/wftask_list.jsp?id='+ $scope.wfFlowId ;
				}, 500);
			});
		}
		
		//  点击取消按钮，跳转到查询页面
		$scope.backHis = function() {
			location.href = basePath+'/system/flowManager/wftask_list.jsp?id='+ $scope.wfFlowId;
		};
		

	
		
});

